package com.weike.wk_android.view.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.trello.rxlifecycle3.components.RxActivity;
import com.weike.wk_android.R;
import com.weike.wk_android.impl.ETPhoneListener;
import com.weike.wk_android.utils.Utils;
import com.weike.wk_android.widget.toast.MyToast;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ForgetPasswordActivity extends RxActivity {
    @BindView(R.id.phone)
    EditText phone;
    @BindView(R.id.forget_code)
    EditText forgetCode;
    @BindView(R.id.new_password)
    EditText newPassword;
    @BindView(R.id.confirm_password)
    EditText confirmPassword;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_password);
        ButterKnife.bind(this);

        initListener();
    }

    /**
     * 手机号绑定事件
     */
    private void initListener() {
        phone.addTextChangedListener(new ETPhoneListener(phone));
    }

    @OnClick({R.id.forget_close, R.id.get_code, R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.forget_close:
                close();
                break;
            case R.id.get_code:
                getCode();
                break;
            case R.id.submit:
                submit();
                break;
        }
    }

    /**
     * 提交
     */
    private void submit() {
        String username = Utils.replace(phone.getText().toString());
        String code = forgetCode.getText().toString();
        String new_pass = newPassword.getText().toString();
        String confir_pass = confirmPassword.getText().toString();

        if (TextUtils.isEmpty(username)) {
            MyToast.showToast(this, Utils.getString(R.string.phone_null));
        } else if(TextUtils.isEmpty(code)) {
            MyToast.showToast(this, Utils.getString(R.string.code_null));
        } else if (!TextUtils.equals(new_pass, confir_pass)) {
            MyToast.showToast(this, Utils.getString(R.string.compare_pass));
        } else if (Utils.regPatternsPassword(this, new_pass)) {
            return;
        }

        // 发送请求
    }

    /**
     * 获取短信验证码
     */
    private void getCode() {
    }

    /**
     * 关闭页面
     */
    private void close() {
        finish();
    }
}
